import FsUtil from './utils/FsUtil.js'
import Lng from './utils/LngUtil.js'

const { join, sep } = require('path')

// 非中文全部显示英文
const defaultContent = { startup: false }
const os = require('os')
const configDir = `${os.homedir()}${sep}.statsme${sep}config`
const configFile = 'data.json'

class config {
  static getData = () => {
    // console.log(this.configDir)
    const configFilePath = join(configDir, configFile)
    if (!FsUtil.isExist(configDir)) {
      FsUtil.mkDirs(configDir)
    }
    if (!FsUtil.isExist(configFilePath)) {
      const language = Lng.getSysShortLng() // 'en', 'zh'
      defaultContent.lng = language === 'zh' ? 'zh' : 'en'
      FsUtil.write(configFilePath, JSON.stringify(defaultContent))
    }
    // console.log(configFilePath)
    const content = FsUtil.read(configFilePath)
    return JSON.parse(content.toString())
  }

  static writeData = (content) => {
    const configFilePath = join(configDir, configFile)
    FsUtil.write(configFilePath, content)
  }
}

export default config
